<extend name="Base/common"/>

<block name="style">
    <link href="__CSS__/help.css" rel="stylesheet" type="text/css"/>
</block>

<block name="body">
    <div class="col-md-12">
        <include file="Public/user_info"/>
        <include file="Public/_top_menu"/>
    </div>

    <div class="col-md-12 ">
        <div class="bgwhite pull-left" style="min-height: 690px;width: 100%;margin-top: 0">
            <div class="help_h" style="">
                <a href="{:U('help/index/production',array('id'=>$help_id))}" class="pull-left active" style="width: 120px;">帮忙作品</a>
                <a  href="{:U('help/index/evaluate',array('id'=>$help_id))}" class="pull-left" style="width: 120px;">帮忙评价</a>

                <a href="{:U('help/index/detail',array('id'=>$help_id))}" class="pull-left " style="width: 120px;">帮忙描述</a>
            </div>


            <div class="col-xs-12">
                <form class="form-horizontal ajax-form" role="form" action="{:U('help/index/publishwork')}"
                      method="post" id="edit-article-form">
                    <input type="hidden" name="help_id" value="{$help_id}">
                    <div class="col-md-12">
                        <div class="col-xs-12 col-md-3">
                            <a class="upload_cover" href="{:U('help/index/_uploadcover')}">
                                <div style="height: 215px;width:215px;border: 1px solid #ccc;line-height: 215px;text-align: center;margin-top: 30px">
                                   <php>if($work){</php> <img style="width: 100%" id="show_picture" src="{$work.cover|get_cover='path'}"/>
                                    <php>}else{</php>
                                    上传封面
                                        <php>}</php>
                                </div>
                            </a>
                            <input type="hidden" name="cover_id" value="{$work.cover}">
                        </div>
                        <div class="col-xs-12 col-md-9 publish_right">

                            <div class="form-group has-feedback">
                                <div class="publish_right_label">标题</div>
                                <div class=" col-sm-5">
                                    <input type="text" name="title" class="form-control form_check" check-type="Text"
                                           check-length="4,20" value="{$work.title}">
                                </div>
                            </div>
                            <div class="form-group has-feedback" style="margin-top: 33px;">
                                <div class="publish_right_label">详细说明</div>
                                <div class=" col-sm-8">
                                    <textarea name="detail" class="form-control form_check" check-type="Text"
                                              check-length="0,150" value="" style="height: 95px">{$work.detail}</textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="clearfix dashed"></div>
                    <div class=" col-sm-12" style="padding-bottom: 20px">
                        <div class="publish_right_label" style="margin-top: 10px;">添加视频：</div>
                        <div class="text-center" style="margin-left: 15px;">
                            <div class="pull-left" style="margin-top: 10px;margin-bottom: 5px;">请输入视频播放页面的链接地址 如http://v.youku.com/v_show/id_Xjg3Nj4MDMy.html</div>
                            <input type="text" name="video_url" class=" pull-left form-control" value="{$work.video.0}" style="width: 60%;height: 35px;">
                            <input type="hidden" name="video" value="{$work.video.0}">
                            <a class="pull-left btn btn-primary button_change" id="add_video">添加视频</a>
                            <div class="pull-left" id="show_video" style="margin-top: 10px">
                                <php>if($work['video'][1]){</php>
                                <embed src="{$work.video.1}" wmode="transparent" allowfullscreen="true" type="application/x-shockwave-flash" width="525" height="420"></embed>
                                <php>}</php>
                            </div>
                        </div>
                    </div>

                    <div class="clearfix dashed"></div>
                    <div class=" col-sm-12" style="">
                        <div class="publish_right_label" style="margin-top: 10px;">添加图片：</div>
                          <div class="pull-left publish_work_image_list" id="add_image" style="margin-left: 15px;">
                            <input type="hidden" name="image" id="image_{$unid}" value="{:implode(',',$work['image'])}">
                            <div class="img-list clearfix">
                                <div style="color: #959595;">支持JPG JPEG PNG 图片格式，单张图片最大8M</div>
                                <ul id="ul_{$unid}" style="-webkit-padding-start: 0px;">

                                    <php>if($work){</php>
                                    <volist name="work.image" id="image">
                                        <li id="li_{$unid}_{$key}"><img src="{$image|get_cover='path'}" width="80" height="80" />
                                            <a href="javascript:;" onclick="multi_upload.removeImage('{$unid}', '{$key}','{$image}' )">
                                                <span class="del">删除</span>
                                            </a>
                                        </li>
                                    </volist>

                                    <php>}</php>



                                    <li id="btn_{$unid}"><input style="display:none" id="uploadify_{$unid}" type="file" /></li>
                                </ul>
                            </div>
                        </div>

                    </div>
                    <div class="col-xs-12 text-center" style="padding:30px 0 ">
                        <button type="submit" class="btn btn-primary button_change">完成发布</button>
                    </div>

                </form>
            </div>

        </div>
    </div>
    <script>
        $(function () {
            bindUploadCover();
        });
        function bindUploadCover() {
            $('.upload_cover').magnificPopup({
                type: 'ajax',
                overflowY: 'scroll',
                modal: true,
                callbacks: {
                }
            });
        }
    </script>
    <script type="text/javascript" src="__PUBLIC__/Core/js/form_check.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Core/js/multi_upload.js"></script>
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>

    <script>
        var unid = "{$unid}",
        fileSizeLimit = "{$fileSizeLimit}"
        $('#uploadify_'+unid).uploadify({
            formData: {
                attach_type: 'feed_image',
                upload_type: 'image',
                thumb: 1,
                width: 100,
                height: 100,
                cut: 1,
                PHPSESSID: "<?php echo session_id(); ?>"
            },
            fileSizeLimit: fileSizeLimit,
            fileTypeDesc: 'Image Files',
            fileTypeExts:  '*.jpg; *.png; *.gif;',
            swf: '__STATIC__/uploadify/uploadify.swf',
            uploader: "{:U('Home/File/uploadPicture',array('session_id'=>session_id()))}",
            width: 80,
            height: 80,
            buttonImage: '__ROOT__/Addons/InsertImage/_static/image/add-photo-multi.png',
            queueSizeLimit:0,
            queueID: true,
            overrideEvents: ['onSelectError', 'onDialogClose'],
            onUploadSuccess : function(file, data, response) {
                var jsondata = $.parseJSON(data);
                multi_upload.removeLoading(unid);
                if (jsondata.status === 1) {
                    $('#btn_'+unid).before($('<li id="li_'+unid+'_'+file.index+'"><img src="'+jsondata.path+'" width="80" height="80" /><a href="javascript:;" onclick="multi_upload.removeImage(\''+unid+'\', '+file.index+', '+jsondata.id+')"><span class="del">删除</span></a></li>').fadeIn('slow'));
                }
                multi_upload.upAttachVal('add', jsondata.id,unid);
            },
            onUploadStart: function (file) {
                multi_upload.addLoading(unid);
            }    ,
            onSelectError: function (file, errorCode, errorMsg) {
                switch (errorCode) {
                    case -100:
                        toast.error('选择的上传数目超过，您还能上传'+errorMsg+'个图片');
                        break;
                    case -110:
                        toast.error("文件 [" + file.name + "] 大小超出系统限制的" + $('#uploadify_'+unid).uploadify('settings', 'fileSizeLimit') + "大小", 4);
                        break;
                    case -120:
                        toast.error("文件 [" + file.name + "] 大小异常");
                        break;
                    case -130:
                        toast.error("文件 [" + file.name + "] 类型不正确");
                        break;
                }
            },
            onFallback: function () {
                toast.error('您未安装FLASH控件，无法上传！请安装FLASH控件后再试');
            }
        });
    </script>

    <script>
        $('#add_video').click(function () {
            var url = $('input[name=video_url]').val();
            $.post(U('help/index/getVideoInfo'), {url: url}, function (res) {
                eval("var data=" + res);
                if (data.boolen == 1 && data.title == 1) {
                    $('input[name=video]').val(url);
                    toast.success('添加成功');
                    $('#show_video').html('<embed src="' + data.data.flash_url + '" wmode="transparent" allowfullscreen="true" type="application/x-shockwave-flash" width="525" height="420"></embed>');
                } else {
                    $('input[name=video]').val('');
                    toast.error(data.message);
                }
            });

        })


    </script>
</block>




